using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;

using InformationSchema;

namespace Core
{
    public class Schema
    {
        private string name = string.Empty;
        private string default_character_set_name = string.Empty;

        public string Name
        {
            get { return name; }
        }

        public string DefaultCharacterSetName
        {
            get { return default_character_set_name; }
        }

        private static Schema CreateFromReader(DbDataReader reader)
        {
            Schema schema = new Schema();

            schema.default_character_set_name = reader.GetString(1);
            schema.name = reader.GetString(0);

            return schema;
        }

        public static List<Schema> FindAll()
        {
            string query = "SELECT S.`SCHEMA_NAME`, S.`DEFAULT_CHARACTER_SET_NAME`  FROM information_schema.SCHEMATA S";
            List<Schema> schemas = new List<Schema>();

            using (DbDataReader reader = DatabaseHelper.ExecuteReader(query))
            {
                while (reader.Read())
                {
                    schemas.Add(CreateFromReader(reader));
                }
            }

            return schemas;
        }
    }
}
